<?php
class Page_Be_Cron_CurrencyRates extends Page{
	function __construct() {
		parent::__construct();
	}

	public function defaultAction() {
		$json = file_get_contents(conf('EXCHANGE_RATES_API_URL'));
		$json = (array) json_decode($json);

		$dateToday = date("Y-m-d");
		$currencyRateObj = new Db_Locale_CurrencyRates();
		$currencyRateObj->cr_date = $dateToday;

		$listCurrencyArray = Db_Locale_Currencies::findAll();

		foreach($listCurrencyArray as $currency) {
			$currencyRateObj->id = NULL;
			$currencyRateObj->cr_currency_id = $currency->id;
			$currencyRateObj->cr_rate = $json["rates"]->{$currency->cu_iso_name};
			$currencyRateObj->save(true);
		}
		return array();
	}
}